﻿using System;
using OutlookContactsSync.Domain.Properties;
using OutlookContactsSync.Domain.Presenters;
using OutlookContactsSync.Domain.Views;
using OutlookContactsSync.Services;

namespace OutlookContactsSync.Presenters
{
    public class OutlookSyncStatusPresenter : IOutlookSyncStatusPresenter
    {
        private IOutlookSyncStatusView _view;

        public OutlookSyncStatusPresenter(IOutlookSyncStatusView view)
        {
            View = view;
        }

        public void InitView()
        {
            View.AmountOfUsersSynced =      Resources.AmountOfContactsSynced + Settings.Default.LastSyncNewUsersAdded;

            View.AmountOfUsersRemoved =     Resources.AmountOfContactsRemoved + Settings.Default.LastSyncUsersRemoved;

            View.AmountOfUsersUpdated =     Resources.AmountOfContactsUpdated + Settings.Default.LastSyncUsersUpdated;

            View.LastSuccesFullSyncDate = (string.IsNullOrEmpty(Settings.Default.LastSyncDateTime))
                                            ? Resources.NoSuccesFullSync
                                            : Resources.LastSuccesfullSync + Settings.Default.LastSyncDateTime;

            View.LastSuccesfullSyncDuration = (Settings.Default.LastSyncTimeSpan.Seconds == 0)
                                            ? string.Empty
                                            : Resources.LastSyncTook + Convert.ToInt32(Settings.Default.LastSyncTimeSpan.TotalSeconds) + " " + Resources.Seconds;

            View.ShowForm();
        }

        #region IOutlookSyncMainPresenter Members

        public IOutlookSyncStatusView View
        {
            private get
            {
                Guard.ArgumentNotNull(_view, "view");
                return _view;
            }
            set
            {
                _view = value;
            }
        }

        #endregion
    }
}